clear all
use "Full Subsidy Data.dta", clear

*keep if (energy_label_eu=="A+"|energy_label_eu=="A+++"|energy_label_eu=="A++")


by id country, sort: egen firstyear=min(year)

encode country,gen(icountry)

/*
drop if units==.
drop if units==0
by id country firstyear, sort: egen firstmonth=min(month) if firstyear==year
tab firstmonth
*/

********************************************************************************

preserve

**Austria, refrigerators and freezers, diffusion of energy class A++ 

sort date country

**program starts 2009 September, graph can start 2006, include products introduced 2005 or later, focus on years starting 2006

by date country, sort: egen sumunits_e=sum(units)  	 if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A++" 
by date country, sort: egen sumunits_a=sum(units)    if (category=="refrigerator"|category=="freezer")                          

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2008| (year==2009 & month<9)) & (year >=2007 | (year==2006 & month>=9))
predict ratio_within, resid
browse date icountry year month ratio ratio_within

gen treat=0
replace treat=1 if country=="Austria"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2007 | (year==2006 & month>=9)) & year <=2010 & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if (year >=2007 | (year==2006 & month>=9)) & year <=2010 & treat==0, connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of A++ Refrigerators & Freezers")graphregion(color(white)) tline(2009m9, lcolor(gray) lpattern(longdash)) tline(2010m9, lcolor(gray) lpattern(longdash))  xtitle("") legend(lab (1 "Austria") lab (2 "All excl. Austria"))

graph export "Plot_AT1_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_AT1.png", as(png) replace

restore


********************************************************************************

preserve

**Austria, washing machines, diffusion of energy class A++ 

sort date country

**program starts 2010 April, graph can start 2007, include products introduced 2005 or later, focus on years starting 2006

by date country, sort: egen sumunits_e=sum(units)  	 if (category=="washing machine") & energy_label_eu=="A++" 
by date country, sort: egen sumunits_a=sum(units)    if (category=="washing machine")                          

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2009| (year==2010 & month<4)) & (year >=2007 | (year==2006 & month>=4))
predict ratio_within, resid

gen treat=0
replace treat=1 if country=="Austria"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2007 | (year==2006 & month>=4)) & year <=2011 & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if (year >=2007 | (year==2006 & month>=4)) & year <=2011 & treat==0, connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of A++ Washing Machines")graphregion(color(white)) tline(2010m4, lcolor(gray) lpattern(longdash))  xtitle("") legend(lab (1 "Austria") lab (2 "All excl. Austria"))

graph export "Plot_AT2_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_AT1.png", as(png) replace

restore

********************************************************************************

preserve

**Hungary, refrigerators and freezers, diffusion of energy class A++ and A+++

sort date country

**second program starts 2016 September, due to earlier program graph can start 2013, include products introduced 2011 or later, focus on years starting 2012

by date country, sort: egen sumunits_e=sum(units)  	 if (category=="refrigerator"|category=="freezer")  & (energy_label_eu=="A++"|energy_label_eu=="A+++")  
by date country, sort: egen sumunits_a=sum(units)    if (category=="refrigerator"|category=="freezer")                                                     

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2015 | (year==2016 & month < 9)) & (year >=2014 | (year==2013 & month>=9))
predict ratio_within, resid

drop if country=="Croatia"
gen treat=0
replace treat=1 if country=="Hungary"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2014 | (year==2013 & month>=9)) & year <=2018 & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if year<=2018 & (year >=2014 | (year==2013 & month>=9)) & treat==0, connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of  A++ & A+++ Refrigerators & Freezers")graphregion(color(white)) tline(2015m2, lcolor(gray) lpattern(longdash)) tline(2016m9, lcolor(gray) lpattern(longdash))  xtitle("") legend(lab (1 "Hungary") lab (2 "All excl. Hungary & Croatia"))

graph export "Plot_HU1_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_HU1.png", as(png)  replace

restore


********************************************************************************

preserve

**Hungary, refrigerators and freezers, diffusion of energy class A+ 

sort date country

by date country, sort: egen sumunits_e=sum(units)  	 if (category=="refrigerator"|category=="freezer")  & (energy_label_eu=="A+")                           
by date country, sort: egen sumunits_a=sum(units)    if (category=="refrigerator"|category=="freezer")                                                     

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2015 | (year==2016 & month < 9)) & (year >=2014 | (year==2013 & month>=9))
predict ratio_within, resid

drop if country=="Croatia"
gen treat=0
replace treat=1 if country=="Hungary"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2014 | (year==2013 & month>=9)) & year <=2018 & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if (year >=2014 | (year==2013 & month>=9)) & year <=2018 & treat==0, connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of  A+ Refrigerators & Freezers")graphregion(color(white)) tline(2015m2, lcolor(gray) lpattern(longdash)) tline(2016m9, lcolor(gray) lpattern(longdash))  xtitle("") legend(lab (1 "Hungary") lab (2 "All excl. Hungary & Croatia"))

graph export "Plot_HU2_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_HU2.png", as(png) replace

restore

********************************************************************************

preserve

**Hungary, washing machines, diffusion of energy class A+++

sort date country

**program starts 2015 October, include products introduced 2011 or later, focus on years starting 2012

by date country, sort: egen sumunits_e=sum(units)  	 if (category=="washing machine") & (energy_label_eu=="A+++")    
by date country, sort: egen sumunits_a=sum(units)    if (category=="washing machine")                               

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2014 | (year==2015 & month < 10)) & (year >=2013 | (year==2012 & month>=10))
predict ratio_within, resid

drop if country=="Croatia"
gen treat=0
replace treat=1 if country=="Hungary"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2013 | (year==2012 & month>=10)) & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if (year >=2013 | (year==2012 & month>=10)) & treat==0 ,connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of A+++ Washing Machines")graphregion(color(white)) tline(2015m10, lcolor(gray) lpattern(longdash))   xtitle("") legend(lab (1 "Hungary") lab (2 "All excl. Hungary & Croatia"))

graph export "Plot_HU3_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_HU3.png", as(png) replace

restore

********************************************************************************

preserve

**Hungary, washing machines, diffusion of energy class A+ & A++

sort date country

**program starts 2015 October, include products introduced 2011 or later, focus on years starting 2012

by date country, sort: egen sumunits_e=sum(units)     if (category=="washing machine") & (energy_label_eu=="A+"|energy_label_eu=="A++")  
by date country, sort: egen sumunits_a=sum(units)     if (category=="washing machine")                                                  

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2014 | (year==2015 & month < 10)) & (year >=2013 | (year==2012 & month>=10))
predict ratio_within, resid

drop if country=="Croatia"
gen treat=0
replace treat=1 if country=="Hungary"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2013 | (year==2012 & month>=10)) & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if (year >=2013 | (year==2012 & month>=10)) & treat==0 ,connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of A+ and A++ Washing Machines")graphregion(color(white)) tline(2015m10, lcolor(gray) lpattern(longdash))   xtitle("") legend(lab (1 "Hungary") lab (2 "All excl. Hungary & Croatia"))

graph export "Plot_HU4_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_HU4.png", as(png) replace

restore

********************************************************************************

preserve

**Croatia, washing machines, diffusion of energy class A+++

sort date country

**program starts 2015 June, include products introduced 2011 or later, focus on years starting 2012

by date country, sort: egen sumunits_e=sum(units)  	 if (category=="washing machine") & (energy_label_eu=="A+++")  
by date country, sort: egen sumunits_a=sum(units)    if (category=="washing machine")                             

gen ratio=sumunits_e/sumunits_a

collapse (mean) ratio year month icountry, by(date country)

regress ratio i.icountry if (year<=2014 | (year==2015 & month < 6)) & (year >=2013 | (year==2012 & month>=6))
predict ratio_within, resid

drop if country=="Hungary"
gen treat=0
replace treat=1 if country=="Croatia"
collapse (mean) ratio_within year month, by(date treat)

twoway scatter ratio_within date if (year >=2013 | (year==2012 & month>=3)) & treat==1, connect(l)  msize(small) msymbol(Oh) mcolor(black) lcolor(black)||scatter ratio_within date if (year >=2013 | (year==2012 & month>=3)) & treat==0, connect(l)  msize(small) msymbol(Th) mcolor(sienna) lcolor(sienna) title("") ytitle("Market Share of  A+++  Washing Machines")graphregion(color(white)) tline(2015m6, lcolor(gray) lpattern(longdash)) tline(2015m10, lcolor(gray) lpattern(longdash))  xtitle("") legend(lab (1 "Croatia") lab (2 "All excl. Croatia & Hungary"))


graph export "Plot_HR1_36.eps", as(eps) fontface("Times New Roman") replace
*graph export "Plot_HR1.png", as(png) replace

restore




